package edu.nf.project.services.storeOperation.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import edu.nf.project.entitys.entity.storeOperation.convention.operate.RefundImage;
import edu.nf.project.mappers.storeOperation.convention.RefundImageMapper;
import edu.nf.project.services.storeOperation.RefundImageService;
import edu.nf.project.utils.FileUploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author CSY
 * @date 2025 - 06 - 20
 */
@Service
public class RefundImageServiceImpl implements RefundImageService {
    @Autowired
    private RefundImageMapper refundImageMapper;

    @Override
    public void insertRefundImage(MultipartFile file, RefundImage refundImage) {
        //图片上传并获取到图片名
        String fileName = FileUploadUtil.fileUpload(file);
        refundImage.setImagePath(fileName);
        //添加到数据库
        refundImageMapper.insert(refundImage);
    }

    @Override
    public List<RefundImage> ListRefundImage(int rrId) {
        LambdaQueryWrapper<RefundImage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RefundImage::getRrId, rrId)
                .orderByAsc(RefundImage::getSortOrder);
        return refundImageMapper.selectList(queryWrapper);
    }
}
